package demoMod.icebreaker.powers;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.powers.AbstractPower;
import demoMod.icebreaker.IceBreaker;

public class DoubleBlockPower extends AbstractPower {
    public static final String POWER_ID = IceBreaker.makeID("DoubleBlockPower");
    private static final PowerStrings powerStrings;
    public static final String NAME;
    public static final String[] DESC;
    private boolean gainFromSelf = false;

    public DoubleBlockPower(AbstractCreature owner, int amount) {
        this.owner = owner;
        this.amount = amount;
        this.ID = POWER_ID;
        this.name = NAME;
        this.updateDescription();
        this.loadRegion("defenseNext");
    }

    @Override
    public void updateDescription() {
        this.description = String.format(DESC[0], this.amount);
    }

    @Override
    public void onGainedBlock(float blockAmount) {
        addToBot(new AbstractGameAction() {
            @Override
            public void update() {
                if (!gainFromSelf) {
                    DoubleBlockPower.this.flash();
                    addToTop(new GainBlockAction(DoubleBlockPower.this.owner, (int)blockAmount));
                    addToTop(new ReducePowerAction(DoubleBlockPower.this.owner, DoubleBlockPower.this.owner, DoubleBlockPower.this, 1));
                }
                DoubleBlockPower.this.gainFromSelf = !gainFromSelf;
                isDone = true;
            }
        });
    }

    static {
        powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
        NAME = powerStrings.NAME;
        DESC = powerStrings.DESCRIPTIONS;
    }
}
